#!/usr/bin/ruby
# -*- ruby -*-
#
# http://www.reddit.com/r/dailyprogrammer/comments/17f3y2/012813_challenge_119_easy_change_calculator/

DIVISORS = {
    :quarters => 0.25,
    :dimes    => 0.10,
    :nickels  => 0.05,
    :pennies  => 0.01,
}

ARGV.each do |c|
    c = c.to_f

    change = {
        :quarters => 0,
        :dimes    => 0,
        :nickels  => 0,
        :pennies  => 0,
    }

    change[:quarters] = (c / DIVISORS[:quarters]).to_i
    c = (c - change[:quarters] * DIVISORS[:quarters])

    change[:dimes] = (c / DIVISORS[:dimes]).to_i
    c = (c - change[:dimes] * DIVISORS[:dimes])

    change[:nickels] = (c / DIVISORS[:nickels]).to_i
    c = (c - change[:nickels] * DIVISORS[:nickels])

    change[:pennies] = (c / DIVISORS[:pennies]).round

    puts change.to_a.
        reject { |(c, v)| v == 0}.
        sort { |a, b| DIVISORS[b.first] <=> DIVISORS[a.first]}.
        map { |(c, v)| "#{c} => #{v}"}.
        join(", ")
end
